;layui.define(['jquery','laytpl','form','element','laypage'],function (exports) {
    "use strict";
    let $ = layui.jquery
    , laytpl = layui.laytpl
    , form = layui.form
    , element = layui.element
    , laypage = layui.laypage
    , deps = {
        'laytpl':laytpl
        ,'form':form
        ,'element':element
        ,'laypage':laypage
    }
    , MOD_NAME = 'commini'
    , _const = {
        units:'个十百千万@#%亿^&~'
        ,chars:'零一二三四五六七八九'
    }
    , Commini = function(){
        this.subEvents = {}
        this.tablesOption = {};
        this.renderDOMElOption = {}
    }
    Commini.prototype = {
        constructor:Commini
        ,deps:deps
        //获取自然数,isIncludeZero=true,从0开始
        , times:function(num,isIncludeZero){
            isIncludeZero = isIncludeZero||0;
            let arr = [],i = 0;
            isIncludeZero && (i = -1,isIncludeZero = -1)
            while(num>isIncludeZero){
                num--;
                arr.push(++i);
            }
            return arr;
        }
        //获取json数组中某个字段
        ,getFieldsArr:function(jsonArr,feild) {
            jsonArr = jsonArr || [];
            return jsonArr.map(function(json){
                return json[feild]
            })
        }
        //伪数组转为真数值
        , arrayLike:function(arrLike){
            return Array.from ? Array.from(arrLike) : Array.prototype.slice.call(arrLike);
        }
        , toTwoArray:function(arr,num){
            let rows = [];
            num = num||7;
            arr = arr.concat();
            while(arr.length > 0) {
                rows.push(arr.splice(0, num));
            }
            return rows;
        }
        , arrayConcact:function(){
            let otherArrays = this.arrayLike(arguments)
                ,targetArray = otherArrays.shift()
                ,otherArraysLen = otherArrays.length;
            for(let i=0; i<otherArraysLen; i++){
                try {//ES6
                    targetArray.push(...otherArrays[i]);
                }catch(err){
                    targetArray = targetArray.concat(otherArrays[i]);
                }
            }
        }
        ,arrayPush:function(targetArr,otherArr) {
            Array.prototype.push.apply((targetArr || (targetArr = [])),otherArr);
        }
        ,isEmptyObj:function(obj){
            if(JSON.stringify(obj) == '{}'){
                return true;
            }
            return false;
        }
        , isDOMEl:typeof HTMLElement === 'object'
            ? function(obj) {return obj instanceof HTMLElement;}
            : function(obj) {return obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';}
        , queryAll:function(oParent,selector){
            if(typeof oParent == 'string'){
                selector = oParent
                oParent = null;
            }
            return  !oParent ? oParent.querySelectorAll(selector) : document.querySelectorAll(selector)
        }
        , getEl:function(selector){
            if(this.isDOMEl(selector)){
                return selector;
            }else{
                return document.getElementById(selector);
            }
        }
        , insertAfter:function(newNode,targetNode){
            let parent = targetNode.parentNode;
            if(parent.lastChild == targetNode){
                //向指定父容器中追加子元素
                parent.appendChild(newNode)
            }else{
                //containerEl.innserBefore(newNode,targetNode)
                //在指定父容器中，将newNode追加至targetNode之前
                parent.insertBefore(newNode,targetNode.nextSibling);
            }
        }
        , delEleInArray:function(arr,val){
            return arr.splice(arr.indexOf(val),1);
        }
        , isHasPro:function(obj,pro){
            return obj.hasOwnProperty(pro);
        }
        , reverseStr:function(str){
            return str.trim().replace(/\s+/g,' ').split(' ').reverse().join('');
        }
        //判断客户端类型
        ,os:function(){
            let ua = navigator.userAgent,
                isWindowsPhone = /(?:Windows Phone)/.test(ua),			//手机版window
                isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone, //塞班
                isAndroid = /(?:Android)/.test(ua),				//安卓
                isIos = /\(i[^;]+;( U;)? CPU.+Mac OS X/.test(ua), 	//ios
                isIE = /(?:MSIE)/.test(ua),				//IE
                isFireFox = /(?:Firefox)/.test(ua),		//火狐
                isChrome = /(?:Chrome|CriOS)/.test(ua),	//Chrome
                isPresto = /(?:Presto)/.test(ua),		//opera内核
                isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)), //平板
                isIphone = /(?:iPhone)/.test(ua) && !isTablet,	//iPhone
                isPc = !isIphone && !isAndroid && !isSymbian && !isTablet && !isWindowsPhone, //pc
                isMobile = /AppleWebKit.*Mobile.*/.test(ua);
            return {
                isTablet: isTablet,
                isIphone: isIphone,
                isIos:isIos,
                isIE:isIE,
                isAndroid : isAndroid,
                isChrome: isChrome,
                isMobile:isMobile,
                isPc: isPc
            };
        }
        //获取IE版本
        ,IEV:function(){
            return navigator.userAgent.match(/(?:MSIE\s+(\d)+\.\d)/)[1];
        }
        ,headWordToUpCase:function(str){
            return str.toLowerCase().replace(/\b(\w)|\s(\w)/g,function(word){return word.toUpperCase()})
        }
        /**
         * 判断数据类型
         * var isFunction = isType('function')
         * isFunction(obj)
         */
        , isType:function(type){
            return (obj)=>{
                type = this.headWordToUpCase(type);
                return Object.prototype.toString.call(obj) == `[object ${type}]`;
            }
        }
        //日期处理
        ,date:{
            //小于10补零
            addZero:function(num){
                return num > 9 ? num : "0"+num;
            }
            //格式化时间
            ,formatDate:function(date,separate){
                if(!typeof separate == 'string' && separate != undefined){
                    throw new Error("separate "+separate+" is not string type");
                }
                var separate = separate || '-';
                return date.getFullYear() + separate
                    + this.addZero(date.getMonth() + 1)+ separate
                    + this.addZero(date.getDate())+" "
                    + this.addZero(date.getHours())+":"
                    + this.addZero(date.getMinutes())+":"
                    + this.addZero(date.getSeconds());
            }
            //获取date
            ,getDate:function(dateStr){
                //日期格式yyyy-MM-dd
                let regDate = /^((?:19|20)\d\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/
                if(regDate.test(dateStr)){
                    let dateArr = dateStr.split("-")
                    return new Date(dateArr[0],dateArr[1],dateArr[2],0,0,0)
                }
                return new Date(dateStr);
            }
            //获取时间戳
            ,getTimeStamp:function(date){
                return date.getTime();
            }
            //计算时间差
            ,timeDiffer:function(beginDateStr,endDateStr){
                var startTime = new Date(beginDateStr);
                var endTime = new Date(endDateStr);
                var date= endTime.getTime() - startTime.getTime();
                var days = Math.round(date/(24*3600*1000));
                return days;
            }
            //计算时间差,当beginDateStr,endDateStr相同时，包含这天
            ,timeDifferInclude:function(beginDateStr,endDateStr){
                let days = this.timeDiffer(beginDateStr,endDateStr)+1;
                return days;
            }
            /**
             * set多少天前/后的date
             * date：可以是（时间戳，格式化时间YYYY-MM-dd HH:mm:ss字符串，Date对象）
             */
            ,setManyDays:function(date,manyDays){
                date = new Date(date)
                date.setDate(date.getDate() + (manyDays));
                return date;
            }
            //获取指定年、月的天数
            ,getDays:function(year, month){
                return new Date(year,month,0).getDate();
            }
            //获取某年，某月的第一个天是周几
            ,getFirstDayIsWeek:function(y,m){
                return new Date(y,m-1,1).getDay();
            }
            //获取年月日
            ,getYMD:function(date){
                return {year:date.getFullYear(),month:date.getMonth()+1,day:date.getDate()}
            }
            //获取某年某月上个月days天日期
            ,getPreMonthDays:function(y,m,days){
                let num = []
                ,calNum = this.date.getDays(y,m-1);
                for(let i=calNum-days+1; i<=calNum; i++){
                    num.push(i);
                }
                return num;
            }
            /**
             * 获取日历数据
             * getCalData(Date对象,'prev')--->获取当前年月的前一个月的，日历数据
             * getCalData(Date对象,'next')--->获取当前年月的下一个月的，日历数据
             * getCalData(Date对象,month)--->获取当年的指定月份的，日历数据
             * getCalData(year,month)-->获取2020年8月，日历数据
            * */
            ,getCalData:function(date,month){
                month = month||date.getMonth()+1;
                let isDate = this.isType('date')
                ,dateObj = this.date.getYMD(date)
                ,calData = [];
                if(isDate(date)){
                    month == 'prev' && date.setFullYear(dateObj.year,dateObj.month-1)
                    month == 'next' && date.setFullYear(dateObj.year,dateObj.month+1)
                    typeof month == 'number' && (date = new Date(),date.setFullYear(date.getFullYear(),month-1))
                }else{
                    /^\d{4}$/.test(date) && /^([1-9]|1[0-2]{1})$/.test(month) && (date = new Date(date,month-1))
                }
                let week = this.date.getFirstDayIsWeek(dateObj.year,dateObj.month)
                ,days = this.date.getDays(dateObj.year,dateObj.month)
                ,trs = Math.ceil((days+week)/7)
                ,fullDay = trs*7-week;
                //减去week天，就添加这些天
                Array.prototype.push.apply(calData,getPreMonthDays(dateObj.year,dateObj.month,week));
                Array.prototype.push.apply(calData,this.times(days));
                Array.prototype.push.apply(calData,this.times(fullDay-days));
                return this.toTwoArray(calData);
            }
            //dates:['2020-01','2019-04','2020-09']
            ,getYMDates:function(year,month,dates){
                let days = this.date.getDays(new Date(year,month));
                let regExpStr = year+"-"+this.date.addZero(month)+'-[0-'+days+']'
                , regExp = new RegExp(regExpStr);
                return dates.filter(function(date){
                    return regExp.test(date);
                })
            }
            /**
             * 计时器
             * 参数：num 毫秒数
             */
            /* 例1：convertTime(10*1000)//10秒
             * 例2：convertTime(28*60*1000)//28分钟
             * 例3：convertTime(2*3600*1000)//2个小时
             * 例4：convertTime(2*60*60*1000+28*60*1000+10*1000)//2小时 28分钟 10秒
             * 例5：convertTime(2*3600*1000+3600*1000+60*1000)//3小时 1分钟 0秒
            */
            ,timer:function(num){
                num = parseInt(num/1000);
                var second = num%60
                    ,minute = parseInt(num/60)%60
                    ,hour = parseInt(num/3600);
                return this.addZero(hour)+":"+this.addZero(minute)+":"+this.addZero(second);
            }
            ,getLenTime:function(lenTime,unit){
                //时间单位
                //皮秒，纳秒，微妙，毫秒，秒，分钟，小时，天，月，年
                let units = ['ps','ns','μs','ms','s','m','h','d','m','y']
                //默认时间单位：秒
                unit = unit || 's'
                let index = units.indexOf(unit);
                let baseVal = (units.length - index)
                if(index > 3){

                }
            }
        }
        //动画结束后的回调
        ,animationEnd:function(ele,sucHandle,errHandle){
            //1、获取动画名
            let animateName = function(){
                let animation = {
                    'animation': 'animationend',
                    'OAnimation': 'oAnimationEnd',
                    'MozAnimation': 'mozAnimationEnd',
                    'WebkitAnimation': 'webkitAnimationEnd'
                }
                let animateName = (function(el) {
                    for (let t in animation) {
                        if (el.style[t] !== undefined) {
                            return animation[t];
                        }
                    }
                })(document.createElement('div'));
                return animateName;
            }();
            //2、给ele绑定动画结束的回调
            let animateEndEventListener = function(sucHandle){
                //在每次transitionEnd的事件后执行该函数
               let handleAniEnd = function(e){
                   ele.removeEventListener(animateName,handleAniEnd);
                   sucHandle.call(this,e,ele);
               };
               ele.addEventListener(animateName,handleAniEnd,false);
            }
            animateName ? animateEndEventListener(sucHandle):errHandle(ele);
        }
        ,animateCSS:function(selector, animationName,endBack){
            const ele = this.isDOMEl(selector)? selector : document.querySelector(selector)
            ele.classList.add('animated', animationName)
            this.animationEnd(ele,function () {
                ele.classList.remove('animated', animationName);
                typeof endBack == 'function' && endBack();
            });
        }
        //ajax
        , sendXHR:function(options,done,fail){
            let deffer = $.ajax($.extend({},{
                url:''
                ,type:'post'
                ,dataType:'json'
                ,data:null
                //,contentType:'application/json;charset=utf-8'
            },options));
            typeof done == 'function' && (
                deffer.then((resObj)=>{
                    done.call(null,resObj)
                },(resObj)=>{
                    if(!fail){
                        return commini.msg.error("ajax请求失败！")
                    }
                    typeof fail == 'function' && fail.call(resObj)
                })
            )
            return deffer;
        }
        //重置表单
        , resetForm:function(formId){
            document.getElementById(formId).reset();
        }
        //获取表单数据
        ,getFormData:function(formId){
            return $("#"+formId).serializeArray();
        }
        //添加表单数据
        ,addFormItem:function(formData,name,value){
            formData.push({name:name,value:value})
            return formData;
        }
        //转json对象
        , serializeArrayToJson:function(serializeArray){
            let jsonObj = {}
            serializeArray.map(function(item){
                jsonObj[item.name+''] = item.value
            });
            return jsonObj;
        }
        //获取serialize值
        ,getSerializeVal:function(serializeArray,name){
            for(let i=0,len=serializeArray.length; i<len; i++){
                let item = serializeArray[i]
                if(item.name == name){
                    return {item:item,index:i};
                }
            }
        }
        /**
         * 渲染模板语法
         * tplEl:模板元素
         * pourEl注入元素
         * data:数据
         */
        , renderTpl:function(tplEl,pourEl,data,insertMethod){
            if(typeof data != 'object'){return}
            tplEl = typeof tplEl == 'string'? tplEl : tplEl.innerHTML
            laytpl(tplEl).render(data, function(html){
                if(!insertMethod){
                    pourEl.innerHTML = html;
                }else{
                    typeof insertMethod == 'function' && insertMethod.call(pourEl,html);
                }
            });
        }
        ,isHasScrolled:function(ele,direction){
            ele = ele ? ele : document;
            if(direction==='y'){
                return ele.scrollHeight>ele.clientHeight;
            }else if(direction==='x'){
                return ele.scrollWidth>ele.clientWidth;
            }
        }
        //对象字面量判断
        , isPlainObject:function(obj){
            let flag = false;
            if(!obj || typeof obj != 'object'){return flag;}
            if(obj.constructor.prototype.hasOwnProperty("isPrototypeOf")){
                flag = true;
            }
            return flag;
        }
        //简单节点树，转为父子节点树
        , parentSubTree:function(nodes){
            let nodePoint = {},newNodes = [];
            nodes.forEach(node=>{
                node.children && delete node.children;
            });
            nodes.forEach(node=>{
                nodePoint[node.id] = node
            })
            nodes.forEach((node,i)=>{
                if(node.pid in nodePoint){//if(nodePoint[node.pid])
                    (nodePoint[node.pid].children || (nodePoint[node.pid].children = [])).push(node);
                }else{//不在则是顶级节点
                    newNodes.push(node);
                }
            });
            return newNodes;
        }
        //父子节点树转为简单节点树
        ,parSubTransformSimple:function(nodes,childName){
            childName = childName || 'children'
            let _self = this, simpleNodes = [];
            for(let i = 0; i < nodes.length; i++){
                let node = nodes[i];
                node.pid = null;
                simpleNodes.push(node);
                getchildNode(node)
            }
            return simpleNodes;
            function getchildNode(node){
                let childNode = node[childName];
                childNode.pid = node.id;
                if(childNode){
                    simpleNodes = simpleNodes.concat(_self.parSubTransformSimple(childNode,childName));
                }
            }
        }
        //发布订阅模式
        ,pubSubObj:function(){
            let _self = this , subEvents = _self.subEvents;
            //订阅方法subscribe 类似于on / watcher
            let subscribe = function(eventType,handle){
                    !(eventType in subEvents) && (subEvents[eventType] = [])
                    subEvents[eventType].push(handle);
                }
                //发布函数publish 类似于trigger / observe
                //data是数组
                , publish = function(eventType, data){
                    eventType = subEvents[eventType];
                    for (let i = 0; i < eventType.length; i++) {
                        eventType[i].apply(null, data);
                    }
                }
                //删除全部订阅
                , unSubscribe = function(eventType) {
                    subEvents[eventType] && delete subEvents[eventType]
                }
                //通过handle删除指定订阅
                , unSubscribeByFun = function(eventType,handle){
                    eventType = subEvents[eventType];
                    if (eventType) {
                        let handleIndex = eventType.indexOf(handle);
                        if (handleIndex >= 0) {
                            eventType.splice(handleIndex, 1);
                        }
                    }
                }
            return {
                subscribe,
                publish,
                unSubscribe,
                unSubscribeByFun
            };
        }
        /**
         * 异步渲染dom元素。
         * 支持同步渲染和异步渲染两种方式。异步渲染请指定url、同步渲染请指定data
         * options={
         *  url:'',可选项,url和data请确保其中任意一个有值
         *  dataFormat:可选项，使用时必须把格式化后的数据return
         *  tplEl:必选项,可以是模板元素本身或tplEL的id属性值
         *  mountEl:必选项,数据最终要渲染到那个容器中，可以是模板元素本身或tplEL的id属性值
         *  reload：可选项，是否可被重新加载，默认为false，不重新加载
         *  updateFormControlType:可选项,要更新的表单控件类型。'radio','checkbox','select','all'。若不指定默认是'all'
         * rendered:可选项，渲染完成后的回调
         * }
         * */
        , asyncRenderDOMEl:function(options){
            let setting = $.extend(true,{},{
                mountEl:''
                ,tplEl:''
                ,reload:false
                ,data:[]
                ,url:''
                ,type:'post'
                ,reqParams: null
                ,updateFormControlType:''
                ,page:{
                    isEnable: false
                    //小于pageSize数量时，不显示
                    ,isShow:true
                    ,elem:''
                    ,prop:{
                        pageNum:'page'
                        ,pageSize:'pageSize'
                        ,totalCount:'rowCount'
                    }
                    ,pageNum:1
                    ,pageSize:10
                    ,totalCount:1
                }
                ,pagingData:null
                ,insertMethod:null
                ,dataFormat:null
                ,rendered(data){}
                ,isLoadPage:true//是否是首次加载
            },options)
            ,id = setting.mountEl
            ,page = setting.page
            ,mountEl = setting.mountEl
            ,tplEl = setting.tplEl
            ,url = setting.url
            ,dataFormat = setting.dataFormat
            ,renderDOMEl = function (tplEl,mountEl,data) {
                !setting.insertMethod && (mountEl.innerHTML = '')
                commini.renderTpl(tplEl,mountEl,data,setting.insertMethod)
                //添加是否加载标识
                mountEl.setAttribute('isload',true)
                if(setting.updateFormControlType){
                    if(setting.updateFormControlType == 'all'){
                        form.render();
                    }else{
                        form.render(setting.updateFormControlType);
                    }
                }
                let dftData = Array.isArray(data)?data[0]: data[Object.keys(data)[0]]
                setting.rendered.call(mountEl,data,dftData);
            }
            ,pageHelper = function (page,totalCount) {
                if(page.isEnable && page.elem){
                    page.totalCount = totalCount;
                    if((page.totalCount <= 1 || page.totalCount <= page.pageSize) && !page.isShow){return document.getElementById(page.elem).style.display = 'none'}
                    laypage.render({
                        elem:page.elem
                        ,limit:page.pageSize
                        ,count:page.totalCount
                        ,jump: function(obj,first){
                            //first表示第一次加载
                            if(!first){
                                commini.asyncRenderDOMEl($.extend(true,setting,{
                                    page:{
                                        pageNum:obj.curr
                                    }
                                    ,isLoadPage:false
                                }))
                            }
                        }
                    });
                }
            }
            ,reqParams = function (page,reqParams) {
                return page.isEnable? $.extend(reqParams,{
                    [page.prop.pageNum]:page.pageNum
                    ,[page.prop.pageSize]:page.pageSize
                }):reqParams;
            }(page,setting.reqParams);
            mountEl = !commini.isDOMEl(mountEl) ? commini.getEl(mountEl):mountEl;
            tplEl = !commini.isDOMEl(tplEl) ? commini.getEl(tplEl):tplEl;
            //如果控制不能重复加载并且已经加载了，则不做任何处理
            if(!mountEl){return;}
            if(mountEl.getAttribute('isload') && !setting.reload){return;}
            //如果reload为true则重新加载
            if(mountEl && url || (mountEl && url && setting.reload)){
                commini.sendXHR({
                    url:url
                    ,type:setting.type
                    ,data:reqParams||null
                },(resObj)=>{
                    let pagingData = setting.pagingData? resObj[setting.pagingData]:resObj
                    if(dataFormat){
                        let dataFormats = dataFormat.call(null,resObj);
                        if(dataFormats){
                            renderDOMEl(tplEl,mountEl,dataFormats);
                        }
                    }else{
                        renderDOMEl(tplEl,mountEl,resObj);
                    }
                    setting.isLoadPage && pageHelper(page,pagingData[page.prop.totalCount]||1);
                },(resObj)=>{console.log(options.url+"请求失败！")});
            }else{
                if(!url){
                    if(dataFormat){
                        let dataFormats = dataFormat.call(null,setting.data);
                        renderDOMEl(tplEl,mountEl,dataFormats);
                    }else{
                        renderDOMEl(tplEl,mountEl,setting.data);
                    }
                    setting.isLoadPage && pageHelper(page,setting.data.length||1);
                }
            }
            //保存配置
            commini.renderDOMElOption[id] = setting;
        }

        ,reloadRenderDOMEl:function(mountId,options){
            commini.asyncRenderDOMEl($.extend(true,commini.renderDOMElOption[mountId]||{},options))
        }
        /**
         * 监听选项卡切换
         * */
        ,listenerTabCar:function(filterId,callback){
            element.on('tab('+filterId+')', function(data){
                typeof callback == 'function' && callback.call(this,data);
            });
        }
        ,render:function(moduleName,object,layFilter){
            if(!deps[moduleName]){return console.error(moduleName+'未定义！');}
            return deps[moduleName].render(object,layFilter||'');
        }
        ,contains:function(moutEl,targetEl){
            let moutEls = Array.from(document.querySelectorAll(moutEl));
            for(let i = 0,len = moutEls.length; i < len; i++){
                moutEl = moutEls[i]
                if(moutEl.contains(targetEl)){
                    return true;
                }
            }
            return false;
        }
        ,pageHelper:function(options){
            return laypage.render($.extend({},{
                elem: ''
                ,count: 1
                ,limit:10
                ,jump: function(obj,first){
                    //first表示是否是第一次加载
                    if(!first){

                    }
                }
            },options));
        }
        ,splitQueryStr:function (obj) {
            let args = "?";
            Object.keys(obj).forEach(function(key){
                let val = obj[key]||''
                args += key+"="+encodeURIComponent(val)+"&";
            });
            return args.substring(0,args.length-1);
        }
        ,getQueryStr:function(pattern){
            let argStr = pattern=='hash' ? location.hash.substring(1) : /^.+\?(.+)$/.exec(location.href)[1]
            ,argArr = argStr.indexOf('#') > -1 ? argStr.split("#")[0].split("&"): argStr.split('&')
            ,params = {};
            argArr.forEach(param => {
                if (/=/.test(param)) { // 处理有 value 的参数
                    let [key, val] = param.split('='); // 分割 key 和 value
                    val = decodeURIComponent(val); // 解码 //加密：encodeURIComponent()
                    val = /^\d+$/.test(val) ? parseFloat(val) : val; // 判断是否转为数字
                    if (params.hasOwnProperty(key)) {
                        params[key] = [].concat(params[key], val);
                    } else {
                        params[key] = val;
                    }
                }
            });
            return params;
        }
        ,resetFormEl:function(formEl){
            formEl.checked = !formEl.checked;
            formEl.value = formEl.checked ? 0 : 1;
            form.render(formEl.getAttribute('type'));
        }
        ,GB2312UnicodeConverter:{
            //中文到Unicode
            ToUnicode: function (str) {
                var txt = escape(str).toLocaleLowerCase().replace(/%u/gi, '\\u');
                return txt.replace(/%7b/gi, '{').replace(/%7d/gi, '}').replace(/%3a/gi, ':').replace(/%2c/gi, ',').replace(/%27/gi, '\'').replace(/%22/gi, '"').replace(/%5b/gi, '[').replace(/%5d/gi, ']').replace(/%3D/gi, '=').replace(/%20/gi, ' ').replace(/%3E/gi, '>').replace(/%3C/gi, '<').replace(/%3F/gi, '?').replace(/%5c/gi, '\\');
            }
            //Unicode到中文
            , ToGB2312: function (str) {
                return unescape(str.trim().replace(/\\u/gi, '%u'));
            }
        }
        ,numberToChinese:function(number){
            let a=(number+'').split(''),s=[],_self=this;
            if(a.length>12){
                throw new Error('too big');
            }else{
                for(let i=0,j=a.length-1;i<=j;i++){
                    if(j==1||j==5||j==9){//两位数 处理特殊的 1*
                        if(i==0){
                            if(a[i]!='1')s.push(_const.chars.charAt(a[i]));
                        }else{
                            s.push(_const.chars.charAt(a[i]));
                        }
                    }else{
                        s.push(_const.chars.charAt(a[i]));
                    }
                    if(i!=j){
                        s.push(_const.units.charAt(j-i));
                    }
                }
            }
            return s.join('').replace(/零([十百千万亿@#%^&~])/g,function(m,d,b){//优先处理 零百 零千 等
                b=_const.units.indexOf(d);
                if(b!=-1){
                    if(d=='亿')return d;
                    if(d=='万')return d;
                    if(a[j-b]=='0')return '零'
                }
                return '';
            }).replace(/零+/g,'零').replace(/零([万亿])/g,function(m,b){// 零百 零千处理后 可能出现 零零相连的 再处理结尾为零的
                return b;
            }).replace(/亿[万千百]/g,'亿').replace(/[零]$/,'').replace(/[@#%^&~]/g,function(m){
                return {'@':'十','#':'百','%':'千','^':'十','&':'百','~':'千'}[m];
            }).replace(/([亿万])([一-九])/g,function(m,d,b,c){
                c=_const.units.indexOf(d);
                if(c!=-1){
                    if(a[j-c]=='0')return d+'零'+b
                }
                return m;
            });
        }
        ,createForm:function(options) {
            options = $.extend({
                url:null
                ,type:'post'
                ,newWin:true
                ,data:null
            },options);
            let form = document.createElement("form");
            document.body.appendChild(form);
            form.action = options.url;
            form.method = options.type;
            form.target = options.newWin ? '_blank':'_self';
            let data = options.data;
            Array.isArray(data) && data.forEach(function(item,i) {
                let input = document.createElement("input");
                input.type = 'hidden';
                input.value = item.value;
                input.name = item.name;
                form.appendChild(input);
            })
            form.submit();
            form.remove();
        }
    }

    let commini = new Commini();

    exports(MOD_NAME, commini);
})